﻿
namespace Security.Authorizations
{
    using System.Configuration.Provider;

    public abstract class AuthorizationProvider : ProviderBase
    {
        public abstract string ApplicationName { get; set; }
        public abstract int CacheTimeout { get; set; }

        protected AuthorizationProvider()
        {

        }

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes)
        {
            base.Initialize(name, attributes);

            if (!string.IsNullOrEmpty(attributes["cacheTimeout"]))
            {
                this.CacheTimeout = System.Convert.ToInt32(attributes["cacheTimeout"]);
            }

            if (string.IsNullOrEmpty(attributes["applicationName"]))
            {
                attributes.Remove("applicationName");
                attributes.Add("applicationName", Utility.GetDefaultAppName());
                ApplicationName = Utility.GetDefaultAppName();
            }
            else
            {
                string applicationName = attributes["applicationName"];
                ApplicationName = applicationName.Contains("/~/") ? Utility.GetDefaultAppName() : applicationName;
            }
        }

        //ROLESPROVIDER
        public abstract bool IsUserInRole(string username, string roleName);
        public abstract string[] GetRolesForUser(string username);
        public abstract void AddUsersToRoles(string[] usernames, string[] roleNames);
        public abstract void CreateRole(string roleName);
        public abstract bool DeleteRole(string roleName, bool throwOnPopulatedRole);
        public abstract string[] FindUsersInRole(string roleName, string usernameToMatch);
        public abstract string[] GetAllRoles();
        public abstract string[] GetUsersInRole(string roleName);
        public abstract void RemoveUsersFromRoles(string[] usernames, string[] roleNames);
        public abstract bool RoleExists(string roleName);

        //AUTHORIZATIONPROVIDER
        public abstract string[] GetAllRoles(string scopeName);
        public abstract string[] GetAllOperations();
        public abstract string[] GetAllTasks();
        public abstract string[] GetAllTasks(string scopeName);
        public abstract bool RoleExists(string roleName, string scopeName);
        public abstract string[] GetRolesForUser(string username, string scopeName);
        public abstract bool IsUserInRole(string username, string roleName, string scopeName);
        public abstract string[] GetOperationsForUser(string username);
        public abstract string[] GetOperationsForUser(string username, string scopeName);
        public abstract bool IsUserInTask(string username, string taskName);
        public abstract bool IsUserInTask(string username, string taskName, string[] scopeNames);
        public abstract string[] GetTasksForUser(string username);
        public abstract bool AccessCheck(string username, string operationName);
        public abstract string[] AccessCheck(string username, string[] operationNames, string scopeName);
        public abstract string[] AccessCheck(string username, string[] operationNames, string[] scopeNames);
        public abstract bool AccessCheck(string username, string operationName, string[] scopeNames);
        public abstract string[] AccessCheckAnyScope(string username, string[] operationNames, string filterToMatch);        
        public abstract string[] GetTasksForUser(string username, string scopeName);
        public abstract void AddUsersToRoles(string[] usernames, string[] roleNames, string scopeName);
        public abstract void CreateRole(string roleName, string roleAssignmentName, string description, string scopeName);
        public abstract bool DeleteRole(string roleName, bool throwOnPopulatedRole, string scopeName);
        public abstract string[] FindUsersInRole(string roleName, string usernameToMatch, string scopeName);
        public abstract string[] GetUsersInRole(string roleName, string scopeName);
        public abstract void RemoveUsersFromRoles(string[] usernames, string[] roleNames, string scopeName);
        public abstract string[] GetAllScopes();
        public abstract string[] FindUsersInScope(string scopeName, string usernameToMatch);
        public abstract string[] GetScopesForUser(string username);
        public abstract string[] GetScopesForUser(string username, string filterToMatch);
        public abstract string[] GetUsersInScope(string scopeName);
        public abstract bool IsUserInScope(string username, string scopeName);
        public abstract bool ScopeExists(string scopeName);
        public abstract void CreateScope(string scopeName);
        public abstract void DeleteScope(string scopeName);

    }
}
